package com.yunhe.abnormal.service.base;


import com.yunhe.abnormal.domain.base.AbnormalRule;
import com.yunhe.abnormal.dto.AbnormalRuleDTO;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.exception.ObjectNotFoundException;
import com.yunhe.common.exception.UniqueConstraintsException;
import com.yunhe.common.model.PageParam;
import org.springframework.stereotype.Service;
import zju.fes.exp.IllegalExpressionException;
import zju.fes.exp.IncalculableExpressionException;
import zju.fes.exp.UnknownOperatorException;

import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service
public interface AbnormalRuleService {
    
    AbnormalRule create(AbnormalRule abnormalRule) throws UniqueConstraintsException, ArgumentErrorException, ObjectNotFoundException, IncalculableExpressionException, IllegalExpressionException, UnknownOperatorException;

    Iterable<AbnormalRule> create(List<AbnormalRule> abnormalRules) throws ObjectNotFoundException, UniqueConstraintsException, ArgumentErrorException, IncalculableExpressionException, IllegalExpressionException, UnknownOperatorException;

    AbnormalRule update (AbnormalRule abnormalRule) throws UnknownOperatorException, IncalculableExpressionException, IllegalExpressionException, ArgumentErrorException;

    void updateLevel(List<Long> id, Long alarmLevelId) ;

    AbnormalRule findById(Long id);

    Iterable<AbnormalRule> search(Optional<List<Long>> stationIds,
                                  Optional<Long> objectId,
                                  Optional<String> queryStr,
                                  PageParam pageParam);

    void delete(Long id);

    AbnormalRule findByName(String name);

    AbnormalRule findByTitle(String title, Long objectId);

    String getLabel(Long id);

    /**
     * 获得告警规则id和对象的映射map
     */
    Map<String, AbnormalRuleDTO> getRuleDtoMap();

    /**
     * 删除告警规则id和对象的映射map缓存
     */
    void deleteRuleDtoMap();

    /**
     * 根据告警规则id获得电站id
     * @param abnormalRuleId 告警规则id
     */
    Long getStationIdByRuleId(Long abnormalRuleId);

    /**
     * 根据告警规则id获得设备id
     * @param abnormalRuleId 告警规则id
     */
    Long getDeviceIdByRuleId(Long abnormalRuleId);

    /**
     * 根据告警规则id获得设备标题
     * @param abnormalRuleId 告警规则id
     */
    String getDeviceTitleByRuleId(Long abnormalRuleId);

    /**
     * 根据告警规则id获得规则标题
     * @param abnormalRuleId 告警规则id
     */
    String getRuleTitleByRuleId(Long abnormalRuleId);

}
